﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using nplJobs.DB;

namespace nplJobsDAL.Select
{
    public class SelectWhatDataList : DataAccessBase
    {
        public string txt { get; set; }
        public SelectWhatDataList()
        {
            StoredProcedureName = StoredProcedure.Name.spGetWhatData.ToString();
        }

        public List<string> GetWhatData()
        {
            try
            {
                CustomParameterList cpList = new CustomParameterList();
                cpList.Add(new CustomParameter("@What", txt, DbType.String));

                object paramval = null;
                DBHelper db = new DBHelper();
                DataTable dsWhatData = db.ExecuteQueryToDataTable(cpList.ParameterNames, cpList.ParameterValues, cpList.ParameterTypes, ref paramval, null, StoredProcedureName);

                return GetList(dsWhatData);
            }
            catch (Exception)
            {

                throw;
            }
        }

        #region GetList
        private List<string> GetList(DataTable dsWhatData)
        {            
            try
            {
                List<string> lstData = dsWhatData.AsEnumerable().Select(s => s.Field<string>("What")).ToList();
                return lstData;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally { }
        }
        #endregion
    }
}
